<?php
/**
 * 版权所有 (C) 2024 [陕西超拼软件科技有限公司]
 * 本产品使用《Apache-2.0》开源协议，除非遵守许可证（http://www.apache.org/licenses/LICENSE-2.0），否则不得使用
 * 未经许可禁止在本产品的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发
 * 具体说明可前往见闻间官网：https://cc.chaopin100.com/xinxuan 进行查看
 */
declare (strict_types = 1);

namespace app\admin\controller\auth;


use think\response\Json;
use app\admin\controller\Controller;
use app\common\service\ConfigService;

class Role extends Controller
{
    protected $service = null;

    public function initialize()
    { 
        parent::initialize();
        $this->service = new \app\common\service\RoleService();
    }

    /**
     * 列表
     * @return Json
     * @throws \think\db\exception\DbException
     */
    public function list(): Json
    {
        ConfigService::set('role', 'role', 1);
        return success($this->service->list());
    }

    /**
     * 详情
     * @param int $id
     * @return Json
     * @throws BaseException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \Dengje\Pxy\exception\BaseException
     */
    public function detail(): Json
    {
        $id = (int)$this->request->param('id');
        return success($this->service->detail($id));
    }

    /**
     * 添加
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \Dengje\Pxy\exception\BaseException
     */
    public function create(): Json
    {
        return success('创建成功',$this->service->create(request()->param()));
    }

    /**
     * 编辑
     * @param int $id
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \Dengje\Pxy\exception\BaseException
     */
    public function update(): Json
    {
        $id = (int)$this->request->param('id');
        return success('更新成功',$this->service->update($id,request()->param()));
    }

    public function delete(): Json
    {
        $id = (int)$this->request->param('id');
        return success('删除成功',$this->service->delete($id));
    }
}